package cn.chinasyq.photoquan.photo.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader.ImageContainer;
import com.android.volley.toolbox.ImageLoader.ImageListener;

import cn.chinasyq.photoquan.R;
import cn.chinasyq.photoquan.photo.adapter.PhotoPagerTabAdapter;
import cn.chinasyq.photoquan.view.ZoomImageView;
import cn.master.volley.commons.VolleyHelper;

public class PhotoInfoFragment extends Fragment implements PhotoPagerTabAdapter.OnItemFirstShowListener {

    private ZoomImageView zoomImageView;
    private FrameLayout layout;
    private TextView tv_title;
    private TextView tv_content;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_photo_info, container, false);
        zoomImageView = (ZoomImageView) view.findViewById(R.id.zoomImageView);
        tv_title = (TextView)view.findViewById(R.id.tv_title);
        tv_content = (TextView)view.findViewById(R.id.tv_content);
        tv_content.setMovementMethod(new ScrollingMovementMethod());
        if (getArguments().getString("desc")!=null){
            tv_content.setText(getArguments().getString("desc"));
        }else {
            tv_content.setVisibility(View.GONE);
        }
        tv_title.setVisibility(View.GONE);
        layout = (FrameLayout) view.findViewById(R.id.layout);
        VolleyHelper.getImageLoader().get(getArguments().getString("url"), new ImageListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                zoomImageView.setImageBitmap(null);
                zoomImageView.setImageResource(R.mipmap.def);
            }

            @Override
            public void onResponse(ImageContainer response, boolean isImmediate) {
                if (null != response.getBitmap()) {
                    zoomImageView.setImageBitmap(response.getBitmap());
                    layout.setVisibility(View.GONE);
                }
            }
        });
        return view;
    }

    @Override
    public void onItemFirstShow() {

    }
}
